package com.itheima.job3;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //1.创建socket对象，并同时请求与服务端程序建立连接
        new Thread(()->{
            try {
                Socket client = new Socket("127.0.0.1", 6666);
                //2.从socket通道中获取一个字节输出流，用来发送数据给服务端程序
                OutputStream outputStream = client.getOutputStream();
                //3.将低级字节输出流包装成数据输出流
                DataOutputStream dos = new DataOutputStream(outputStream);
                //4.开始写数据
                dos.writeUTF("你好我是客户端小白1");
                dos.close();
                client.close();//释放连接资源
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).start();
        new Thread(()->{
            try {
                Socket client = new Socket("127.0.0.1", 6666);
                //2.从socket通道中获取一个字节输出流，用来发送数据给服务端程序
                OutputStream outputStream = client.getOutputStream();
                //3.将低级字节输出流包装成数据输出流
                DataOutputStream dos = new DataOutputStream(outputStream);
                //4.开始写数据
                dos.writeUTF("你好我是客户端小白2");
                dos.close();
                client.close();//释放连接资源
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).start();
        new Thread(()->{
            try {
                Socket client = new Socket("127.0.0.1", 6666);
                //2.从socket通道中获取一个字节输出流，用来发送数据给服务端程序
                OutputStream outputStream = client.getOutputStream();
                //3.将低级字节输出流包装成数据输出流
                DataOutputStream dos = new DataOutputStream(outputStream);
                //4.开始写数据
                dos.writeUTF("你好我是客户端小白3");
                dos.close();
                client.close();//释放连接资源
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).start();
        new Thread(()->{
            try {
                Socket client = new Socket("127.0.0.1", 6666);
                //2.从socket通道中获取一个字节输出流，用来发送数据给服务端程序
                OutputStream outputStream = client.getOutputStream();
                //3.将低级字节输出流包装成数据输出流
                DataOutputStream dos = new DataOutputStream(outputStream);
                //4.开始写数据
                dos.writeUTF("你好我是客户端小白4");
                dos.close();
                client.close();//释放连接资源
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).start();



    }
}
